# encoding: utf-8
from sqlalchemy_utils import Timestamp

from app.extensions import db
from app.modules.common.dbUtil import createId

from app.modules.vcloud.models import JsonEncoder


class AutoTest(db.Model, JsonEncoder):
    __tablename__ = "case"
    id = db.Column(db.String(255), primary_key = True)
    name = db.Column(db.String(255), nullable = True)
    parent_id = db.Column(db.String(255), nullable = True)
    root_case = db.Column(db.String(255), nullable = True)
    index = db.Column(db.String(255), nullable = True)
    is_case = db.Column(db.String(10), nullable = True)
    path = db.Column(db.Text, nullable = True)

    childs = None

    def __init__(self, name = None, parent_id = None, root_case = None, index = None, is_case = '0', path = None):
        self.id = createId("at")
        self.name = name
        self.parent_id = parent_id
        self.root_case = root_case
        self.index = index
        self.is_case = is_case
        self.path = path

    def to_dict(self):
        return {
            'id': self.id,
            'name': self.name,
            'parent_id': self.parent_id,
            'root_case': self.root_case,
            'index': self.index,
            'is_case': self.is_case,
            'childs': self.childs,
            'path': self.path
        }
